package br.ufal.ic.sd.testes;

import org.junit.*;

import br.ufal.ic.sd.loggerApi.ClientSideConection;
import br.ufal.ic.sd.serverSide.serverOptions.CentralServer;
import static org.junit.Assert.*;

/**
 * The class <code>ClientSideConectionTest</code> contains tests for the class <code>{@link ClientSideConection}</code>.
 *
 * @author Thiago Ribeiro
 * @version $Revision: 1.0 $
 */
public class ClientSideConectionTest {
	
	ClientSideConection clientSideConection;
	CentralServer c ;
	Thread t;
	Thread t1;
	/**
	 * Teste para construtor de {@link ClientSideConection}
	 * @throws Exception
	 */
	@Test
	public void testClientSideConection() throws Exception 
	{
		assertNotNull(clientSideConection);
	}

	/**
	 * Run the String enviarDados(String) method test.
	 * @throws Exception
	 */
	@Test
	public void testEnviarDados() throws Exception 
	{
		clientSideConection.enviarDados("teste");
		
		while(clientSideConection.mensagemValidaRecebida == ""){}
		
		assertEquals("Mensagem salva com sucesso: teste", 
					clientSideConection.mensagemValidaRecebida);
	}


	/**
	 * Perform pre-test initialization.
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		
		//coloco o servidor em uma thread separada;
//		c = new CentralServer();
//		t = new Thread(c);
//		t.start();
		
		//inicio a classe a ser testada;
		clientSideConection =  new ClientSideConection("localhost", 9000);
		t1 = new Thread(clientSideConection);
		t1.start();
	}

	/**
	 * Perform post-test clean-up.
	 * @throws Exception
	 */
	@After
	public void tearDown() throws Exception {

		//c.serverMain.finalizarServidor();
		// Add additional tear down code here
	}

	/**
	 * Launch the test.
	 *
	 * @param args the command line arguments
	 *
	 */
	public static void main(String[] args) {
		new org.junit.runner.JUnitCore().run(ClientSideConectionTest.class);
	}
}